package org.activequant.core.domainmodel.data;

import java.io.Serializable;
import java.util.List;

import org.activequant.core.domainmodel.SeriesSpecification;
import org.activequant.core.domainmodel.marketdepth.MarketDepthEvent;
import org.activequant.core.types.TimeStamp;
import org.activequant.util.exceptions.ValueNotFoundException;
import org.activequant.util.tools.ArrayUtils;

/**
 * A TimeSeries(ArrayList subclass) whose elements are MarketDepthEvent objects.<br/>
 * Holds the following inherited/associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>seriesSpecification(SeriesSpecification)</li>
 * <li>inherited list of elements (List&lt;MarketDepthEvent&gt;)</li>
 * </ul>
 *  @author dmisev
 */
	public class MarketDepthEventSeries extends TimeSeries<MarketDepthEvent> implements Serializable {

		private static final long serialVersionUID = -3722093387498618030L;
		
	    /**
	     * an empty MarketDepthEventSeries constructor.
	     */
	    public MarketDepthEventSeries() {
	    	
	    }

	    /**
	     * constructs  a MarketDepthEventSeries(ArrayList and TimeSeries subclass) using the given marketDepths(List&lt;MarketDepthEvent&gt;) to set its MarketDepthEvent elements.
	     * @param marketDepthEvents
	     */
	    public MarketDepthEventSeries(List<MarketDepthEvent> marketDepths) {
	    	super(marketDepths);
	    }
	    /**
	     * Constructs a MarketDepthEventSeries(ArrayList and TimeSeries subclass) using the given spec(SeriesSpecification) and marketDepths(List&lt;MarketDepthEvent&gt;) to set its associated 
		 * seriesSpecification(SeriesSpecification) and its MarketDepthEvent elements.
	     * @param spec
	     * @param marketDepthEvents
	     */
	    public MarketDepthEventSeries(SeriesSpecification spec, List<MarketDepthEvent> marketDepths) {
	    	super(marketDepths);
	    	setSeriesSpecification(spec);
	    }
	    
	    
	    /**
	     * constructs a MarketDepthEventSeries(ArrayList and TimeSeries subclass) using the given marketDepthEvents(MarketDepthEvent...) to set its MarketDepthEvent elements.
	     * @param candles
	     */
	    public MarketDepthEventSeries(MarketDepthEvent... marketDepthEvents) {
	    	this(ArrayUtils.asList(marketDepthEvents));
	    }
	    /**
	     * Constructs a MarketDepthEventSeries(ArrayList and TimeSeries subclass) using the given spec(SeriesSpecification) and marketDepthEvents(MarketDepthEvent...) to set its associated 
		 * seriesSpecification(SeriesSpecification) and its MarketDepthEvent elements.
	     * @param spec
	     * @param marketDepthEvents
	     */
	    public MarketDepthEventSeries(SeriesSpecification spec, MarketDepthEvent... marketDepthEvents) {
	    	this(marketDepthEvents);
	    	setSeriesSpecification(spec);
	    }
	    /**
	     * Sets the elements of this MarketDepthEventSeries(ArrayList and TimeSeries subclass) with the given marketDepthEvents(MarketDepthEvent...).
	     * @param marketDepthEvents
	     */
	    public void setMarketDepthEvents(MarketDepthEvent... marketDepthEvents) {
	    	setMarketDepthEvents(ArrayUtils.asList(marketDepthEvents));
	    }
	    /**
	     * Sets the elements of this MarketDepthEventSeries(ArrayList and TimeSeries subclass) with the given marketDepthEvents(List&lt;MarketDepthEvent&gt;).
	     * @param marketDepthEvents
	     */
	    public void setMarketDepthEvents(List<MarketDepthEvent> marketDepthEvents) {
	    	clear();
	    	addAll(marketDepthEvents);
	    }
	    /**
	     * returns a MarketDepthEvent[] array containing the elements of this MarketDepthSeries(ArrayList and TimeSeries subclass)
	     * @return
	     */
	    public MarketDepthEvent[] getMarketDepthEvents() {
	    	return ArrayUtils.asArray(this, MarketDepthEvent.class);
	    }
		
	    /**
	     * clone this MarketDepthEventSeries instance.
	     * @return cloned object
	     */
		public MarketDepthEventSeries clone() {
			MarketDepthEvent[] clonedMarketDepthEvents = new MarketDepthEvent[size()];
			MarketDepthEvent[] marketDepthEvents = toArray(new MarketDepthEvent[]{});
			for(int i = 0; i < marketDepthEvents.length; i++) {
				clonedMarketDepthEvents[i] = marketDepthEvents[i].clone();
			}
			MarketDepthEventSeries clone = new MarketDepthEventSeries(seriesSpecification, clonedMarketDepthEvents);
			return clone;
		}
		/**
		 * returns a MarketDepthEventSeries containing the MarketDepthEvent elements whose TimeStamps are within(inclusive) the given start-end(TimeStamp) interval
		 */
	    public MarketDepthEventSeries getTimeFrame(TimeStamp start, TimeStamp end) {
	    	return (MarketDepthEventSeries) super.getTimeFrame(start, end);
	    }
		/**
		 * returns a MarketDepthEventSeries containing the MarketDepthEvent elements within(inclusive) the given start-end(int) index interval
		 */
		public MarketDepthEventSeries subList(int start, int end) throws ValueNotFoundException {
			return (MarketDepthEventSeries) super.subList(start, end);
		}
		/**
		 * returns a MarketDepthEventSeries containing the MarketDepth elements whose TimeStamps are within(inclusive) the given start-end(TimeStamp) interval
		 */
		public MarketDepthEventSeries subList(TimeStamp start, TimeStamp end) throws ValueNotFoundException {
			return (MarketDepthEventSeries) super.subList(start, end);
		}		
		
	}